package com.cskaoyan.gateway.controller.user;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.commons.tool.utils.CookieUtil;
import com.mall.user.IUserService;
import com.mall.user.annotation.Anoymous;
import com.mall.user.dto.UserLoginOutResponse;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author: thz
 * @class: LoginOutController
 */
@RestController
@RequestMapping("user")
public class LoginOutController {

//    @Anoymous
    @GetMapping("loginOut")
    public ResponseData userLoginout(HttpServletRequest request, HttpServletResponse response){
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies) {
            if ("access_token".equals(cookie.getName())){
                cookie.setMaxAge(0);
//                cookie.setDomain("localhost");
                cookie.setPath("/");
                response.addCookie(cookie);
            }
        }
        return new ResponseUtil().setData(null);
    }

}
